{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I like A pizza\n",
      "I like B pizza\n",
      "I like C pizza\n",
      "I like D pizza\n",
      "I really love pizza!\n"
     ]
    }
   ],
   "source": [
    "# 4.1\n",
    "pizza_type = [\"A\", \"B\", \"C\", \"D\"]\n",
    "\n",
    "for type in pizza_type:\n",
    "    print(f\"I like {type} pizza\")\n",
    "    \n",
    "print(\"I really love pizza!\")    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A dog would make a great pet\n",
      "A cat would make a great pet\n",
      "A tiger(huge car) would make a great pet\n",
      "A bear would make a great pet\n",
      "Any of these animals would make a great pet!\n"
     ]
    }
   ],
   "source": [
    "#4.2\n",
    "animal_type = [\"dog\", \"cat\", \"tiger(huge car)\", \"bear\"]\n",
    "\n",
    "for animal in animal_type:\n",
    "    print(f\"A {animal} would make a great pet\")\n",
    "    \n",
    "print(\"Any of these animals would make a great pet!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
     ]
    }
   ],
   "source": [
    "# 4.3\n",
    "for i in range(1,20+1):\n",
    "    print(i, end=\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
     ]
    }
   ],
   "source": [
    "# 4.4\n",
    "num_lst = list(range(1,20 + 1)) #1_000_000 + 1\n",
    "for i in num_lst:\n",
    "    print(i, end = \" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000000 1\n",
      "500000500000\n"
     ]
    }
   ],
   "source": [
    "# 4.5\n",
    "num_lst2 = list(range(1, 1_000_000 + 1))\n",
    "print(max(num_lst2), min(num_lst2))\n",
    "sum = 0\n",
    "for i in num_lst2:\n",
    "    sum += i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 3 5 7 9 11 13 15 17 19 "
     ]
    }
   ],
   "source": [
    "# 4.6\n",
    "num_lst3 = list(range(1,20+1,2))\n",
    "for i in num_lst3:\n",
    "    print(i, end=\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]\n"
     ]
    }
   ],
   "source": [
    "# 4.7\n",
    "num_lst7 = []\n",
    "for i in range(3, 30+1):\n",
    "    if i % 3 == 0:\n",
    "        num_lst7.append(i)\n",
    "\n",
    "print(num_lst7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\n"
     ]
    }
   ],
   "source": [
    "# 4.8\n",
    "num_lst8 = []\n",
    "for i in range(1, 10+1):\n",
    "    num_lst8.append(i**3)\n",
    "\n",
    "print(num_lst8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\n"
     ]
    }
   ],
   "source": [
    "# 4.9\n",
    "num_lst9 = [value ** 3 for value in range(1, 10+1)]\n",
    "print(num_lst9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\n",
      "The first three items in the list are: [1, 8, 27]\n",
      "Three items from the middle of the list are: [64, 125, 216]\n",
      "The last three items in the list are: [1000, 729, 512]\n"
     ]
    }
   ],
   "source": [
    "# 4.10\n",
    "num_lst10 = [value ** 3 for value in range(1, 10+1)]\n",
    "print(num_lst10)\n",
    "\n",
    "print(f\"The first three items in the list are: {num_lst10[:3]}\")\n",
    "print(f\"Three items from the middle of the list are: {num_lst10[3:6]}\")\n",
    "\n",
    "print(f\"The last three items in the list are: {num_lst10[:-4:-1]}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My favorite pizzas are:\n",
      "A B C D E \n",
      "My friend's favorite pizzas are:\n",
      "A B C D F \n"
     ]
    }
   ],
   "source": [
    "# 4.11\n",
    "pizza_type = [\"A\", \"B\", \"C\", \"D\"]\n",
    "friend_pizza = pizza_type[:]\n",
    "pizza_type.append(\"E\")\n",
    "friend_pizza.append(\"F\")\n",
    "\n",
    "print(\"My favorite pizzas are:\")\n",
    "for i in pizza_type:\n",
    "    print(i, end=\" \")\n",
    "print()\n",
    "\n",
    "print(\"My friend's favorite pizzas are:\")\n",
    "for i in friend_pizza:\n",
    "    print(i, end=\" \")\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A B C D E \n",
      "A B G F E \n"
     ]
    }
   ],
   "source": [
    "# 4.12 略\n",
    "# 4.13\n",
    "food_lst = (\"A\", \"B\", \"C\", \"D\", \"E\")\n",
    "\n",
    "for food in food_lst:\n",
    "    print(food, end=\" \")\n",
    "print()\n",
    "\n",
    "# food_lst[2] = \"C\"\n",
    "# TypeError: 'tuple' object does not support item assignment\n",
    "\n",
    "food_lst = (\"A\", \"B\", \"G\", \"F\", \"E\")\n",
    "for food in food_lst:\n",
    "    print(food, end=\" \")\n",
    "print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
